#include <iostream>
#include <vector>
#include <math.h>
using namespace std;

int n, e1, e2, x1, x2;

int a[2][1000];
int t[2][1000];

int tau[2][1000];
int p[2][1000];

static void ReadInput() {
    cin >> n >> e1 >> e2 >> x1 >> x2;

    for (int i = 0; i < 2; ++i)
        for (int j = 0; j < n; ++j)
            cin >> a[i][j];

    for (int i = 0; i < 2; ++i)
        for (int j = 0; j < (n-1); ++j)
            cin >> t[i][j];
}

static void ShowInput() {
    cout << "n=" << n << endl
         << "e1=" << e1 << endl
         << "e2=" << e2 << endl
         << "x1=" << x1 << endl
         << "x2=" << x2 << endl;

    cout << endl << "a:" << endl;
    for (int i = 0; i < 2; ++i) {
        for (int j = 0; j < n; ++j)
            cout << a[i][j] << "\t";
        cout << endl;
    }

    cout << endl << "t:" << endl;
    for (int i = 0; i < 2; ++i) {
        for (int j = 0; j < (n-1); ++j)
            cout << t[i][j] << "\t";
        cout << endl;
    }
}

static void Solve() {
    tau[0][0] = e1;
    tau[1][0] = e2;

    for (int i = 1; i < n; ++i) {
        {
            const int tmp0 = tau[0][i-1] + a[0][i-1];
            const int tmp1 = tau[1][i-1] + a[1][i-1] + t[1][i-1];
            cout << tmp0 << "\t" << tmp1 << endl;

            if (tmp0 < tmp1) {
                tau[0][i] = tmp0;
                p[0][i] = 0;
            } else {
                tau[0][i] = tmp1;
                p[0][i] = 1;
            }
        }
        {
            const int tmp0 = tau[0][i-1] + a[0][i-1] + t[0][i-1];
            const int tmp1 = tau[1][i-1] + a[1][i-1];
            cout << tmp0 << "\t" << tmp1 << endl;

            if (tmp0 < tmp1) {
                tau[1][i] = tmp0;
                p[1][i] = 0;
            } else {
                tau[1][i] = tmp1;
                p[1][i] = 1;
            }
        }
    }

    const int tmp0 = tau[0][n-1] + a[0][n-1] + x1;
    const int tmp1 = tau[1][n-1] + a[1][n-1] + x2;
    const int resTime = (tmp0 < tmp1) ? tmp0 : tmp1;
    cout << "last step:" << (tmp0 < tmp1 ? "0" : "1") << endl; 
    cout << "Result time:" << resTime << endl;
}

static void ShowSolution() {
    cout << "-----------------------------------------------------" << endl;
    cout << endl << "tau:" << endl;
    for (int i = 0; i < 2; ++i) {
        for (int j = 0; j < n; ++j)
            cout << tau[i][j] << "\t";
        cout << endl;
    }

    cout << endl << "p:" << endl;
    for (int i = 0; i < 2; ++i) {
        for (int j = 0; j < (n-1); ++j)
            cout << p[i][j] << "\t";
        cout << endl;
    }
}

int main() {
    ReadInput();
    ShowInput();
    Solve();
    ShowSolution();
    return 0;
}
